﻿using Microsoft.Xna.Framework.Content;
using PenguinForce.Collisions;

namespace PenguinForce
{
    public class LevelTransitionTracker
    {
        #region Constructors

        public LevelTransitionTracker(Microsoft.Xna.Framework.Game game)
        {
            this.Game = game;
            this.Levels = game.Content.Load<string[]>("LevelTransitions");
            this.CurrentLevelIndex = -1;
            this.LoadNextLevel();
        }

        #endregion

        #region Properties

        private Microsoft.Xna.Framework.Game Game { get; set; }

        public string[] Levels { get; private set; }

        public int CurrentLevelIndex { get; set; }

        public string CurrentLevelName
        {
            get
            {
                return this.Levels[this.CurrentLevelIndex];
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// 
        /// </summary>
        /// <returns>False if there are no more levels</returns>
        public bool LoadNextLevel()
        {
            this.CurrentLevelIndex++;
            if (this.CurrentLevelIndex >= Levels.Length)
            {
                return false;
            }
            CollisionManager.Instance.InitializeLevel(this.Game.Content);
            CollisionManager.Instance.LoadLevel(this.CurrentLevelName);

            string introText = CollisionManager.Instance.GetCurrentLevel().m_introText;
            if (!string.IsNullOrEmpty(introText))
            {
                (this.Game.Services.GetService(typeof(IMessageDisplay)) as IMessageDisplay).ShowMessage(introText);
            }
            return true;
        }

        #endregion
    }
}